<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class upload extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->helper(array('form', 'url'));
		$this->load->library('image_lib');
		$this->load->helper("file");

	}

	function index()
	{
		$this->load->view('upload_form', array('error' => ' ' ));
	}

	function do_upload()
	{
		$config['upload_path'] = 'C:\Users\SBI\Desktop\telechargement';
		$config['allowed_types'] = 'gif|jpg|png';
		//$config['encrypt_name'] = FALSE;
		$config['overwrite'] = TRUE;
		$this->load->library('upload', $config);
		$config['image_library'] = 'gd2';
		//$config['width'] = 75;
	    //$config['height'] = 50;
		
      
     
		if ( ! $this->upload->do_upload())
		{
			$error = array('error' => $this->upload->display_errors());

			$this->load->view('upload_form', $error);
		}
		else
		{
			$data = array('upload_data' => $this->upload->data());
	
			$fpath='C:\Users\SBI\Desktop\telechargement\\'.$data['upload_data']['file_name'];
			//'C:\Users\SBI\Desktop\telechargement\\'.$data['upload_data']['image_width']=200;
			//$this->load->library('upload', $config);
			delete_files('C:\Users\SBI\Desktop\telechargement\\'.$data['upload_data']['file_name']);
			//delete('C:\Users\SBI\Desktop\telechargement\\'.$data['upload_data']['file_name'] );
		    $config['image_library'] = 'gd2';
			$config['source_image'] = $fpath;
			$config['create_thumb'] = FALSE;
            $config['maintain_ratio'] = TRUE;
  		
			   $config['width'] = 200;
	           $config['height'] = 200;
		 
			    $this->load->library('image_lib', $config);
			    $this->image_lib->clear();
                $this->image_lib->initialize($config);
                $this->image_lib->resize();
				
			$this->load->view('upload_success', $data);
		}
	}
}
?>